package cn.fxyz.dao.impl;

import java.util.List;

import cn.fxyz.base.impl.BaseDaoImpl;
import cn.fxyz.dao.UserDao;
import cn.fxyz.entity.User;

public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {
	//登录
	public User selectByUser(User user) {
		List<User> users = (List<User>) this.getHibernateTemplate().find("from User where username=? and password=?",user.getUsername(),user.getPassword());
		if(users.size() != 0) {
			return users.get(0);
		}else {
			return null;
		}
	}

	public User selectByCode(String code) {
		String hql = "from User where code=?";
		List<User> find = (List<User>) this.getHibernateTemplate().find(hql, code);
		if(find != null && find.size() > 0) {
			return find.get(0);
		}
		return null;
	}

	public User findByUsername(String username) {
		String hql = "from User where username=?";
		List<User> users = (List<User>) this.getHibernateTemplate().find(hql, username);
		if(users != null && users.size() > 0) {
			return users.get(0);
		}
		return null;
	}

}
